/**
 *
 */
package com.feizhi.common.extractor;

import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.poi.POITextExtractor;
import org.apache.poi.extractor.ExtractorFactory;

/**
 * @author shuaqiu
 */
public class OfficeTextExtractor extends TextExtractor {

    private static final Log LOG = LogFactory.getLog(OfficeTextExtractor.class);

    @Override
    public String extract(final InputStream stream) {
        try {
            final POITextExtractor extractor = ExtractorFactory.createExtractor(stream);
            final String text = extractor.getText();
            extractor.close();

            return text;
        } catch (final Exception e) {
            LOG.error(e.getMessage(), e);
        }

        return "";
    }
}
